<?php
defined('_AppMiage') or die('Restricted access');
if(isEtudiant()){
    if (isset($_GET['fid']) && !empty($_GET['fid']))
    {
        $stage = new Stage($_GET['fid']);
		
		if($global_member->getIdUtilisateur() != $stage->getIdEtudiant())
        {
            ?><script type="text/javascript">history.go(-1);</script><?php
        }
		
        if (isset($_FILES['pdf']))
        {
            $str = Document::upload($_FILES['pdf'], "upload/etudiant/".$global_member->getIdUtilisateur()."/".$_GET['fid']."/", array(".pdf"));
			
			$document = new Document();
            if($str['bool'] === true)
			
            {
				
				$document->setIdStage($_GET['fid']);
                $document->setPath($str['msg']);
				$conversion = Tools::transformDateToTimestamp(date('m/d/Y'));
				$document->setDateUpload($conversion);
				$document->setIdTypeDocument($_POST['typeDocument']);
				$document->setStatut($_POST['confidentialite']);
				$document->save();
				?><script type="text/javascript">history.go(-1);</script><?php
            }
        }
    }
    else
    {
        ?><script type="text/javascript">history.go(-1);</script><?php
    }
}
else
{
    redirectTo();
}
?>